package com.atguigu.core.acc

import org.apache.spark.util.AccumulatorV2

class MyAcc1 extends AccumulatorV2[Int, Int] {
  private var init = 0

  override def isZero: Boolean = init == 0

  override def copy(): AccumulatorV2[Int, Int] = {
    val acc = new MyAcc1
    acc.init = this.init
    acc
  }

  override def reset(): Unit = {
    init = 0
  }

  override def add(v: Int): Unit = {
    init += v
  }


  override def merge(other: AccumulatorV2[Int, Int]): Unit = {
    init += other.value
  }

  override def value: Int = init
}
